<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <img
      src="https://lljq-1301637875.cos.ap-nanjing.myqcloud.com/image_2023914_1694674500054_8f0qbr.png"
      alt=""
    />
    Adidas offers <a href="https://www.adidas.com/us/sale">up to 40% off </a
    >Clothing & Shoes
    <script>
      let text =
        'Adidas offers [up to 40% off] https://www.adidas.com/us/sale Clothing & Shoes';
      let pattern = /\[(.*?)\]\s(https?:\/\/\S+)/;
      let result = text.replace(pattern, '<a href="$2">$1</a>');

      console.log(result);
    </script>
  </body>
</html>
